package com.carqueue.utils;

import cn.hutool.http.HttpRequest;
import org.json.JSONException;
import org.json.JSONObject;

public class AmapUtils {
    public static String[] getlocation(String location) throws JSONException {
        String URL1="https://restapi.amap.com/v3/geocode/geo";
        String ak1="a7437b39331c5c3ca21c5018d0e52bab";
        String body1 = HttpRequest.get(URL1).form("key", ak1)
                .form("address", location).execute().body();
        String jsonData = body1;
        JSONObject jsonObject = new JSONObject(jsonData);
        JSONObject locationObject = jsonObject.getJSONArray("geocodes").getJSONObject(0);

        String string = locationObject.getString("location");
        String[] a=string.split(",");
        return a;
    }
}
